// pages/order-more/order-more.js
import { Home } from "../../models/home";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    productList: [],
    PageIndex: 1,
    loadingType: ""
  },

  async init() {
    let postData = {
      PageIndex: this.data.PageIndex,
      PageRows: 10,
      SortField: "id",
      SortType: "desc"
    };
    const data = await Home.GetDataList(postData);
    if (data.Data.length == 0) {
      this.setData({
        loadingType: "end"
      });
      return;
    }
    data.Data.map(item => {
      item.time = item.CreateTime.split(" ")[0];
      item.img = item.Imags.split(",")[0];
      return item;
    });
    this.setData({
      productList: this.data.productList.concat(data.Data)
    });
    console.log(this.data.productList);
  },

  async goPurchaseOrder(event) {
    const id = event.currentTarget.dataset.id;

    wx.navigateTo({
      url: `/pages/purchase-order/purchase-order?id=${id}`
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.init();
    wx.setNavigationBarTitle({
      title: "发现需求"
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    console.log("onReachBottom");
    this.data.PageIndex++;
    this.setData({
      loadingType: "loading"
    });
    this.init();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {}
});
